<?php
class SettingsController extends AppController {

/**
 * Controller name
 *
 * @var string
 * @access public
 */
	public $name = 'Settings';

/**
 * Models used by the Controller
 *
 * @var array
 * @access public
 */
	public $uses = array('Setting');

/**
 * Helpers used by the Controller
 *
 * @var array
 * @access public
 */
	public $helpers = array('Html', 'Form');


/**
 * Admin prefix
 *
 * @param string $prefix
 * @return void
 * @access public
 */
	public function admin_config($prefix = null) {
		$this->set('title_for_layout', __('%s Config', Inflector::camelize($prefix)));

		if (!empty($this->request->data) && $this->Setting->saveAll($this->request->data['Setting'])) {
			$this->Session->setFlash(__("Settings updated successfully"), 'default', array('class' => 'success'));
			$this->redirect(array('action' => 'prefix', $prefix));
		}

		$settings = $this->Setting->find('all', array(
			'conditions' => array(
				'Setting.key LIKE' => Inflector::camelize($prefix) . '.%',
				'Setting.editable' => 1,
			),
		));
		$this->set(compact('settings'));

		if (count($settings) == 0) {
			$this->Session->setFlash(__("Invalid Setting key"), 'default', array('class' => 'error'));
		}

		$this->set("prefix", $prefix);
		$this->render('admin_config_'. $prefix);
	}
	
}
